package me.twoday.library.mine.component;

import java.util.ArrayList;

import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

/**
 * 모든 리스트뷰에서 사용하는 헬퍼형 어뎁터 클래스 
 * 
 * @author 김학성
 * @since 2012. 4. 24.
 */
@SuppressWarnings("unused")
public class BaseListAdapter extends BaseAdapter implements OnClickListener 
{
	private static final String TAG = "BaseListAdapter";
	private BaseListHandler mListHandler;
	private ArrayList<?> mList;
	private boolean mIsFirstFooterView;
	
	/**
	 * 기본 생성자. 리스트 핸들러를 받는다.
	 * 
	 * @param listHandler 리스트핸들러
	 */
	public BaseListAdapter(BaseListHandler listHandler)
	{
		this.mListHandler = listHandler;
		this.mList = listHandler.getArrayList();
		this.mIsFirstFooterView = true;
	}
	
	/* (non-Javadoc)
	 * @see android.widget.Adapter#getCount()
	 */
	@Override
	public int getCount()
	{
		return mList.size();
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItem(int)
	 */
	@Override
	public Object getItem(int position)
	{
		return mList.get(position);
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getItemId(int)
	 */
	@Override
	public long getItemId(int position)
	{
		return position;
	}

	/* (non-Javadoc)
	 * @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
	 */
	@Override
	public View getView(int position, View convertView, ViewGroup parent)
	{
		convertView = mListHandler.getRowView(position, convertView);
		convertView.setOnClickListener(this);
		
		return convertView;
	}

	/* (non-Javadoc)
	 * @see android.view.View.OnClickListener#onClick(android.view.View)
	 */
	@Override
	public void onClick(View view)
	{
		mListHandler.onRowClick(view);
	}
}
